package user

import (
	"github.com/bgmp/config"
	"github.com/bgmp/handler"
	"github.com/bgmp/middleware"
	"github.com/bgmp/model"
	"github.com/gin-gonic/gin"
)

func (b Base) GetUserInfo(c *gin.Context, req *GetUserInfoRequest) *GetUserInfoResponse {
	u := &model.User{}
	u.ID = middleware.GetUserId(c)
	err := u.Get(config.DB)
	if err != nil {
		handler.Errorf(c, "用户不存在")
		return nil
	}
	detail := model.UserDetail{}
	detail.UserId = u.ID
	err = detail.GetByUserId(config.DB)
	if err != nil {
		handler.Errorf(c, err.Error())
		return nil
	}
	return &GetUserInfoResponse{
		Username:   u.Username,
		Avatar:     u.Avatar,
		UserDetail: detail,
	}
}

type GetUserInfoRequest struct {
}

type GetUserInfoResponse struct {
	Username string `json:"username"`
	Avatar   string `json:"avatar"`
	model.UserDetail
}
